package com.foodie.map;

import org.junit.Before;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class MapStudy {

    Map<String,String> map=new HashMap<>();

    //初始化
    @Before
    public void test0(){
        map.put("1","name");
        map.put("2","age");
        map.put("3","sex");
    }

    @Test
    public void test1(){
        //map中是否含有某key
        System.out.println(map.containsKey("1"));
        //map中是否含有某value
        System.out.println(map.containsValue("name"));
    }

    @Test
    public void test2(){
        //map中key集合
        for (String s : map.keySet()) {
            System.out.println(s);
        }
    }

    //遍历Map
    @Test
    public void test3(){
        //map中value集合
        for (Map.Entry<String, String> s : map.entrySet()) {
            System.out.println("key:"+s.getKey()+" value:"+s.getValue());
        }
    }








}
